package com.yiwenup.leetcode.offer;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
 */
public class No003 {
    public int findRepeatNumber1(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (set.contains(num)) {
                return num;
            } else {
                set.add(num);
            }
        }
        return -1;
    }

    public int findRepeatNumber2(int[] nums) {
        int[] temp = new int[nums.length];
        for (int num : nums) {
            if (temp[num] > 0) return num;
            temp[num]++;
        }
        return -1;
    }
}
